
  <!DOCTYPE html>
  <html lang="zh-CN"  >
  <head>
  <meta charset="utf-8">
  

  

  

  
  <script>window.icon_font = '4552607_tq6stt6tcg';window.clipboard_tips = {"success":"复制成功(*^▽^*)","fail":"复制失败 (ﾟ⊿ﾟ)ﾂ"};</script>
  
  
  <title>
    c++基础 |
    
    LBCH&#39;Blog
  </title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin><link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=Mulish:400,400italic,700,700italic%7CNoto%20Serif%20SC:400,400italic,700,700italic%7CUbuntu%20Mono:400,400italic,700,700italic&display=swap"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Mulish:400,400italic,700,700italic%7CNoto%20Serif%20SC:400,400italic,700,700italic%7CUbuntu%20Mono:400,400italic,700,700italic&display=swap" media="print" onload="this.media&#x3D;&#39;all&#39;">
  
    <link rel="preload" href="//at.alicdn.com/t/c/font_4552607_tq6stt6tcg.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  
  
<link rel="stylesheet" href="/css/loader.css">

  <meta name="description" content="一. 基础知识1. 文字的输入与输出 输入  相当于从键盘上获取信息赋值给一个容器 代码示例: 123456789#include&lt;iostream&gt;using namespace std;int main()&#123;    数据类型 变量名;    cin &gt;&gt; 变量名;    cout &lt;&lt; 变量名 &lt;&lt; endl;&#125;     输出">
<meta property="og:type" content="article">
<meta property="og:title" content="c++基础">
<meta property="og:url" content="http://example.com/2024/06/14/C++%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="LBCH&#39;Blog">
<meta property="og:description" content="一. 基础知识1. 文字的输入与输出 输入  相当于从键盘上获取信息赋值给一个容器 代码示例: 123456789#include&lt;iostream&gt;using namespace std;int main()&#123;    数据类型 变量名;    cin &gt;&gt; 变量名;    cout &lt;&lt; 变量名 &lt;&lt; endl;&#125;     输出">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-06-14T14:16:00.342Z">
<meta property="article:modified_time" content="2024-06-29T20:02:47.721Z">
<meta property="article:author" content="LBCH">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="LBCH'Blog" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/images/favicon.ico">
  
  
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="https://npm.webcache.cn/photoswipe@5.4.4/dist/photoswipe.css">

  
  
  
  
<script src="https://npm.webcache.cn/pace-js@1.2.4/pace.min.js"></script>

  
    
<link rel="stylesheet" href="https://npm.webcache.cn/wowjs@1.1.3/css/libs/animate.css">

    
<script src="https://npm.webcache.cn/wowjs@1.1.3/dist/wow.min.js"></script>

    <script>
      new WOW({
        offset: 0,
        mobile: true,
        live: false
      }).init();
    </script>
  
  
    <script src="/sw.js"></script>
  
<meta name="generator" content="Hexo 7.2.0"></head>

  <body>
    
  <div id='loader'>
    <div class="loading-left-bg loading-bg"></div>
    <div class="loading-right-bg loading-bg"></div>
    <div class="spinner-box">
      <div class="loading-taichi">
        <svg width="150" height="150" viewBox="0 0 1024 1024" class="icon" version="1.1" xmlns="https://www.w3.org/2000/svg" shape-rendering="geometricPrecision">
          <path d="M303.5 432A80 80 0 0 1 291.5 592A80 80 0 0 1 303.5 432z" fill="#ff6e6b" />
          <path d="M512 65A447 447 0 0 1 512 959L512 929A417 417 0 0 0 512 95A417 417 0 0 0 512 929L512 959A447 447 0 0 1 512 65z" fill="#fd0d00" />
          <path d="M512 95A417 417 0 0 1 929 512A208.5 208.5 0 0 1 720.5 720.5L720.5 592A80 80 0 0 0 720.5 432A80 80 0 0 0 720.5 592L720.5 720.5A208.5 208.5 0 0 1 512 512A208.5 208.5 0 0 0 303.5 303.5A208.5 208.5 0 0 0 95 512A417 417 0 0 1 512 95" fill="#fd0d00" />
        </svg>
      </div>
      <div class="loading-word">少女祈祷中...</div>
    </div>
  </div>
  </div>
  <script>
    var time = null;
    var startLoading = () => {
      time = Date.now();
      document.getElementById('loader').classList.remove("loading");
    }
    var endLoading = () => {
      if (!time) {
        document.body.style.overflow = 'auto';
        document.getElementById('loader').classList.add("loading");
      } else {
        if (Date.now() - time > 500) {
          time = null;
          document.body.style.overflow = 'auto';
          document.getElementById('loader').classList.add("loading");
        } else {
          setTimeout(endLoading, 500 - (Date.now() - time));
          time = null;
        }
      }
    }
    window.addEventListener('DOMContentLoaded', endLoading);
    document.getElementById('loader').addEventListener('click', endLoading);
  </script>

<div id="copy-tooltip" style="pointer-events: none; opacity: 0; transition: all 0.2s ease; position: fixed;top: 50%;left: 50%;z-index: 999;transform: translate(-50%, -50%);color: white;background: rgba(0, 0, 0, 0.5);padding: 10px 15px;border-radius: 10px;">
</div>

    <div id="container">
      <div id="wrap">
        <div id="header-nav">
  <nav id="main-nav">
    
      <span class="main-nav-link-wrap">
        <span class="main-nav-icon"></span>
        <a class="main-nav-link" href="/">首页</a>
      </span>
    
      <span class="main-nav-link-wrap">
        <span class="main-nav-icon"></span>
        <a class="main-nav-link" href="/archives">归档</a>
      </span>
    
    <a id="main-nav-toggle" class="nav-icon"></a>
  </nav>
  <nav id="sub-nav">
    
      <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS 订阅"></a>
    
    
    
  </nav>
</div>
<header id="header">
  
    
      <img fetchpriority="high" src="/images/banner.webp" alt="c++基础">
    
  
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <div id="logo-wrap">
        
          
          
            <a href="/" id="logo">
              <h1>c++基础</h1>
            </a>
          
        
      </div>
      
        
        <h2 id="subtitle-wrap">
          
        </h2>
      
    </div>
  </div>
</header>

        <div id="content" class="outer">
          
          <section id="main"><article id="post-C++基础" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    <div class="article-meta">
      <div class="article-date wow slideInLeft">
  <a href="/2024/06/14/C++%E5%9F%BA%E7%A1%80/" class="article-date-link">
    <time datetime="2024-06-14T14:16:00.342Z" itemprop="datePublished">2024-06-14</time>
  </a>
</div>

      

    </div>
    <div class="hr-line"></div>
    

    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="一-基础知识"><a href="#一-基础知识" class="headerlink" title="一. 基础知识"></a>一. 基础知识</h1><h2 id="1-文字的输入与输出"><a href="#1-文字的输入与输出" class="headerlink" title="1. 文字的输入与输出"></a>1. 文字的输入与输出</h2><ul>
<li>输入</li>
</ul>
<p>相当于从键盘上获取信息赋值给一个容器</p>
<p>代码示例:</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    数据类型 变量名;</span><br><span class="line">    cin &gt;&gt; 变量名;</span><br><span class="line">    cout &lt;&lt; 变量名 &lt;&lt; endl;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<ul>
<li>输出</li>
</ul>
<p>可以在控制台显示变量的值或文字, 数字等信息</p>
<p>代码示例:</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; <span class="string">&quot;输出的内容&quot;</span> &lt;&lt; endl;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="2-注释"><a href="#2-注释" class="headerlink" title="2. 注释"></a>2. 注释</h2><p>作用:在代码中加一些说明和解释, 方便自己或其他程序员阅读代码</p>
<p>两种注释:</p>
<ul>
<li>单行注释 <code>// 描述信息</code></li>
</ul>
<p>​		通常放在一行代码的上方, 或者一条语句的末尾, 对该行代码说明</p>
<ul>
<li>多行注释 <code>/*描述信息*/</code></li>
</ul>
<p>​		通常放在一段代码上方, 对该段代码做整体解释</p>
<p>​	<code>提示:编译器在编译代码时, 会忽略注释内容</code></p>
<h2 id="3-变量"><a href="#3-变量" class="headerlink" title="3. 变量"></a>3. 变量</h2><p>作用:给一段指定的内存空间起名, 方便操作和段内存</p>
<p>语法:<code>数据类型 变量名 = 初始值</code></p>
<h2 id="4-常量"><a href="#4-常量" class="headerlink" title="4. 常量"></a>4. 常量</h2><p>作用:用于记录不可更改的值</p>
<p>定义方式:</p>
<p>​	1.  #define宏常量:<code>#define 常量名 常量值</code></p>
<p>​		通常在文件上方定义, 表示一个常量</p>
<p>​	2.  const修饰的变量:<code>const 数据类型 常量名 = 常量值</code></p>
<p>​		通常在变量定义前加关键字const, 修饰该变量为常量, 不可修改</p>
<h2 id="5-关键字"><a href="#5-关键字" class="headerlink" title="5. 关键字"></a>5. 关键字</h2><p>作用:关键字是C++预先保留的单词(标识符)</p>
<p>​	在定义变量或者常量时, 不要用关键字</p>
<p>C++保留字如下:</p>
<table>
<thead>
<tr>
<th align="center">asm</th>
<th align="center">do</th>
<th align="center">if</th>
<th align="center">return</th>
<th align="center">typedef</th>
</tr>
</thead>
<tbody><tr>
<td align="center">auto</td>
<td align="center">double</td>
<td align="center">inline</td>
<td align="center">short</td>
<td align="center">typeid</td>
</tr>
<tr>
<td align="center">bool</td>
<td align="center">dynamic_cast</td>
<td align="center">int</td>
<td align="center">signed</td>
<td align="center">typename</td>
</tr>
<tr>
<td align="center">break</td>
<td align="center">else</td>
<td align="center">long</td>
<td align="center">sizeof</td>
<td align="center">union</td>
</tr>
<tr>
<td align="center">case</td>
<td align="center">enum</td>
<td align="center">mutable</td>
<td align="center">static</td>
<td align="center">unsighed</td>
</tr>
<tr>
<td align="center">catch</td>
<td align="center">explicit</td>
<td align="center">namespace</td>
<td align="center">static_cast</td>
<td align="center">using</td>
</tr>
<tr>
<td align="center">char</td>
<td align="center">export</td>
<td align="center">new</td>
<td align="center">struct</td>
<td align="center">virtual</td>
</tr>
<tr>
<td align="center">class</td>
<td align="center">extern</td>
<td align="center">operator</td>
<td align="center">switch</td>
<td align="center">void</td>
</tr>
<tr>
<td align="center">const</td>
<td align="center">false</td>
<td align="center">private</td>
<td align="center">template</td>
<td align="center">volatile</td>
</tr>
<tr>
<td align="center">const_cast</td>
<td align="center">float</td>
<td align="center">protected</td>
<td align="center">this</td>
<td align="center">wchar_t</td>
</tr>
<tr>
<td align="center">continue</td>
<td align="center">for</td>
<td align="center">public</td>
<td align="center">throw</td>
<td align="center">while</td>
</tr>
<tr>
<td align="center">default</td>
<td align="center">friend</td>
<td align="center">register</td>
<td align="center">true</td>
<td align="center">try</td>
</tr>
<tr>
<td align="center">delete</td>
<td align="center">goto</td>
<td align="center">reinterpret_cast</td>
<td align="center"></td>
<td align="center"></td>
</tr>
</tbody></table>
<p><code>提示:在给变量或者常量起名称的时候, 不要用C++的关键字, 否则会产生歧义</code></p>
<h2 id="6-标识符命名规则"><a href="#6-标识符命名规则" class="headerlink" title="6. 标识符命名规则"></a>6. 标识符命名规则</h2><p>作用:C++规定给标识符(变量, 常量)命名时, 有一套自己的规则</p>
<p>​	1. 标识符不能是关键字</p>
<p>​	2. 标识符只能由字母, 数字, 下划线组成</p>
<p>​	3. 第一个字符必须为字母或下划线</p>
<p>​	4. 标识符中字母区分大小写</p>
<p><code>建议:给标识符命名时, 争取做到见名知意的效果,方便自己和他人的阅读</code></p>
<h1 id="二-数据类型"><a href="#二-数据类型" class="headerlink" title="二. 数据类型"></a>二. 数据类型</h1><p>C++规定在创建一个变量或者常量时, 必须要指定出相应的数据类型, 否则无法给变量或者常量分配内存</p>
<h2 id="1-整型"><a href="#1-整型" class="headerlink" title="1. 整型"></a>1. 整型</h2><p>作用:整型变量表示的是整数类型的数据</p>
<p>C++中能够表示整数类型有以下几种方式, 区别在于所占内存空间不同:</p>
<table>
<thead>
<tr>
<th>数据类型</th>
<th>占用空间</th>
<th>取值范围</th>
</tr>
</thead>
<tbody><tr>
<td>short(短整型)</td>
<td>2字节</td>
<td>-32768 到 32767</td>
</tr>
<tr>
<td>int(整型)</td>
<td>4字节</td>
<td>-2147483648 到 2147483647</td>
</tr>
<tr>
<td>long(长整型)</td>
<td>Windows为4字节, Linux为4字节(32位), 8字节(64位)</td>
<td>-2147483648 到 2147483647</td>
</tr>
<tr>
<td>long long(长长整型)</td>
<td>8字节</td>
<td>-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807</td>
</tr>
</tbody></table>
<h2 id="2-sizeof关键字"><a href="#2-sizeof关键字" class="headerlink" title="2. sizeof关键字"></a>2. sizeof关键字</h2><p>作用:利用sizeof关键字可以统计数据类型所占内存大小</p>
<p>语法:<code>sizeof(数据类型/变量)</code></p>
<p>整型结论:short &lt; int &lt;&#x3D; long &lt;&#x3D; long long</p>
<h2 id="3-浮点型"><a href="#3-浮点型" class="headerlink" title="3. 浮点型"></a>3. 浮点型</h2><p>作用:用于表示小数</p>
<p>浮点型变量分为两种:</p>
<p>​	1. 单精度float</p>
<p>​	2. 双精度double</p>
<p>两者的区别在于表示的有效数字范围不同</p>
<table>
<thead>
<tr>
<th>数据类型</th>
<th>占用空间</th>
<th>有效数字范围</th>
</tr>
</thead>
<tbody><tr>
<td>float</td>
<td>4字节</td>
<td>7位有效数字</td>
</tr>
<tr>
<td>double</td>
<td>8字节</td>
<td>15到16位有效数字</td>
</tr>
</tbody></table>
<p>注意:1. 浮点型中的有效数字范围包括小数点以前和小数点以后的;</p>
<p>​		 2. 在定义float时是从double转换成float的, 还需要在附的值的后面再加上一个f</p>
<p>​		 3. 默认情况下输出一个小数, 会显示六位有效数字</p>
<p>提示:科学计数法在C++中同样适用, 表示为<code>aeb</code>, 相当于a乘以10的b次方</p>
<h2 id="4-字符型"><a href="#4-字符型" class="headerlink" title="4. 字符型"></a>4. 字符型</h2><p>作用:字符型变量用于显示单个字符</p>
<p>语法:<code>char 变量名 = &#39;字符&#39;</code></p>
<p>​		<code>char 变量名 = &quot;字符串&quot; </code></p>
<p>注意:1. 在显示字符型变量时, 用单引号将字符括起来, 不要用双引号</p>
<p>​		 2. 单引号内只能有一个字符, 不可以是字符串</p>
<p>C和C++中的字符型变量只占用1字节</p>
<p>字符型变量并不是把字符本身放在内存中存储, 而是将对应的ASCII编码放入到存储单元</p>
<p>ASCII码大致由以下两部分组成:</p>
<p>​	1.  ASCII非打印控制字符:ASCII表上的数字0-31分配给了控制字符, 用于控制像打印机等一些外围设备</p>
<p>​    2.  ASCII打印字符: 数字32-126分配给了能在键盘上找到的字符, 当查看或打印文档时就会出现</p>
<h2 id="5-转义字符"><a href="#5-转义字符" class="headerlink" title="5. 转义字符"></a>5. 转义字符</h2><p>作用:用于表示一些不能显示出来的ASCII字符</p>
<p>现阶段我们常用的转义字符有:<code>\n, \\, \t</code></p>
<table>
<thead>
<tr>
<th>转义字符</th>
<th>含义</th>
<th>ASCII码值(十进制)</th>
</tr>
</thead>
<tbody><tr>
<td>\a</td>
<td>警报</td>
<td>007</td>
</tr>
<tr>
<td>\b</td>
<td>退格(BS), 将当前位置移到前一列</td>
<td>008</td>
</tr>
<tr>
<td>\f</td>
<td>换页(FF) , 将当前位置移到下页开头</td>
<td>012</td>
</tr>
<tr>
<td>\n</td>
<td>换行(LF), 将当前位置移到下一行开头</td>
<td>010</td>
</tr>
<tr>
<td>\r</td>
<td>回车(CR), 将当前位置移到本行开头</td>
<td>013</td>
</tr>
<tr>
<td>\t</td>
<td>水平制表(HT), 跳到下一个TAB位置</td>
<td>009</td>
</tr>
<tr>
<td>\v</td>
<td>垂直制表(VT)</td>
<td>011</td>
</tr>
<tr>
<td>\\</td>
<td>代表一个反斜杠字符”\“</td>
<td>092</td>
</tr>
<tr>
<td>\‘</td>
<td>代表一个单引号(撇号)字符</td>
<td>039</td>
</tr>
<tr>
<td>\“</td>
<td>代表一个双引号字符</td>
<td>034</td>
</tr>
<tr>
<td>?</td>
<td>代表一个问号</td>
<td>063</td>
</tr>
<tr>
<td>\0</td>
<td>数字0</td>
<td>000</td>
</tr>
<tr>
<td>\ddd</td>
<td>8进制转义字符, d范围0~7</td>
<td>3位8进制</td>
</tr>
<tr>
<td>\xhh</td>
<td>16进制转义字符, h范围0<del>9</del>, <del>a</del>f, A~F</td>
<td>3位16进制</td>
</tr>
</tbody></table>
<h2 id="6-字符串型"><a href="#6-字符串型" class="headerlink" title="6. 字符串型"></a>6. 字符串型</h2><p>作用:用于表示一串字符</p>
<p>两种风格:</p>
<p>​	1. C语言风格:<code>char 变量名[] = &quot;字符串值&quot;</code></p>
<p>​	2. C++风格:<code>string 变量名 = &quot;字符串值&quot;</code></p>
<p>​		注意:在使用string类型时在有的版本需要引用<string>头文件</p>
<h2 id="7-布尔型"><a href="#7-布尔型" class="headerlink" title="7. 布尔型"></a>7. 布尔型</h2><p>作用:布尔数据类型代表真或假的值</p>
<p>bool类型只有两个值:</p>
<p>​	1. true—真(本质是1)</p>
<p>​	2. false—假(本质是0)</p>
<p>bool类型占1字节大小</p>
<h2 id="8-数据的输入"><a href="#8-数据的输入" class="headerlink" title="8. 数据的输入"></a>8. 数据的输入</h2><p>作用:用于从键盘获取数据</p>
<p>关键字:cin</p>
<p>语法:<code>cin &gt;&gt; 变量名</code></p>
<p>​	注意:此处的变量名需要提前定义其数据类型, 且输入的内容必须和定义的数据类型相符合</p>
<h1 id="三-运算符"><a href="#三-运算符" class="headerlink" title="三. 运算符"></a>三. 运算符</h1><p>作用:用于执行代码的运算</p>
<p>常见的运算符:</p>
<table>
<thead>
<tr>
<th>运算符类型</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>算术运算符</td>
<td>用于处理四则运算</td>
</tr>
<tr>
<td>赋值运算符</td>
<td>用于将表达式的值赋给变量</td>
</tr>
<tr>
<td>比较运算符</td>
<td>用于表达式的比较, 并返回一个真值(true)或假值(false)</td>
</tr>
<tr>
<td>逻辑运算符</td>
<td>用于根据表达式的值返回真值(true)或假值(false)</td>
</tr>
</tbody></table>
<h2 id="1-算术运算符"><a href="#1-算术运算符" class="headerlink" title="1. 算术运算符"></a>1. 算术运算符</h2><p>作用:用于处理四则运算</p>
<p>算术运算符包括以下符号:</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>术语</th>
<th>示例</th>
<th>结果</th>
</tr>
</thead>
<tbody><tr>
<td>+</td>
<td>正号</td>
<td>+3</td>
<td>3</td>
</tr>
<tr>
<td>-</td>
<td>负号</td>
<td>-3</td>
<td>-3</td>
</tr>
<tr>
<td>+</td>
<td>加</td>
<td>10+5</td>
<td>15</td>
</tr>
<tr>
<td>-</td>
<td>减</td>
<td>10-5</td>
<td>5</td>
</tr>
<tr>
<td>*</td>
<td>乘</td>
<td>10*5</td>
<td>50</td>
</tr>
<tr>
<td>&#x2F;</td>
<td>除</td>
<td>10&#x2F;2</td>
<td>5</td>
</tr>
<tr>
<td>%</td>
<td>取模(取余)</td>
<td>10%3</td>
<td>1</td>
</tr>
<tr>
<td>++</td>
<td>前置递增</td>
<td>a&#x3D;2;b&#x3D;++a;</td>
<td>a&#x3D;3;b&#x3D;3;</td>
</tr>
<tr>
<td>++</td>
<td>后置递增</td>
<td>a&#x3D;2;b&#x3D;a++;</td>
<td>a&#x3D;3;b&#x3D;2;</td>
</tr>
<tr>
<td>–</td>
<td>前置递减</td>
<td>a&#x3D;2;b&#x3D;–a;</td>
<td>a&#x3D;1;b&#x3D;1;</td>
</tr>
<tr>
<td>–</td>
<td>后置递减</td>
<td>a&#x3D;2;b&#x3D;a–;</td>
<td>a&#x3D;1;b&#x3D;2;</td>
</tr>
</tbody></table>

      
    </div>
    <footer class="article-footer">
      <blockquote class="article-copyright">
    <p><strong>本文作者：</strong>LBCH @ LBCH'Blog</p>
    <p><strong>本文链接：</strong><a href="http://example.com/2024/06/14/C++%E5%9F%BA%E7%A1%80/">http://example.com/2024/06/14/C++%E5%9F%BA%E7%A1%80/</a></p>
    <p><strong>本文标题：</strong>c++基础</p>
    
    
    <p><strong>本文版权：</strong>本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh"><span class="icon-creative-commons"></span>BY-NC-SA</a> 许可协议。转载请注明出处！</p>
  </blockquote>
      
      
      
      
      
      

    </footer>
  </div>
  
    
  <nav id="article-nav" class="wow fadeInUp">
    
      <div class="article-nav-link-wrap article-nav-link-left">
        
          
          
            <img data-src="/images/banner.webp" data-sizes="auto" alt="python爬虫" class="lazyload">
          
        
        <a href="/2024/06/23/%E7%88%AC%E8%99%AB/"></a>
        <div class="article-nav-caption">前一篇</div>
        <h3 class="article-nav-title">
          
            python爬虫
          
        </h3>
      </div>
    
    
  </nav>


  
</article>






</section>
          
            <aside id="sidebar">
  <div class="sidebar-wrap wow fadeInRight wrap-sticky">
    
      <div class="sidebar-toc-sidebar"><div class="sidebar-toc">
  <h3 class="toc-title">文章目录</h3>
  <div class="sidebar-toc-wrapper toc-div-class" >
      
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80-%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86"><span class="toc-number">1.</span> <span class="toc-text">一. 基础知识</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%96%87%E5%AD%97%E7%9A%84%E8%BE%93%E5%85%A5%E4%B8%8E%E8%BE%93%E5%87%BA"><span class="toc-number">1.1.</span> <span class="toc-text">1. 文字的输入与输出</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E6%B3%A8%E9%87%8A"><span class="toc-number">1.2.</span> <span class="toc-text">2. 注释</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E5%8F%98%E9%87%8F"><span class="toc-number">1.3.</span> <span class="toc-text">3. 变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%B8%B8%E9%87%8F"><span class="toc-number">1.4.</span> <span class="toc-text">4. 常量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">1.5.</span> <span class="toc-text">5. 关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E6%A0%87%E8%AF%86%E7%AC%A6%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99"><span class="toc-number">1.6.</span> <span class="toc-text">6. 标识符命名规则</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C-%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.</span> <span class="toc-text">二. 数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%95%B4%E5%9E%8B"><span class="toc-number">2.1.</span> <span class="toc-text">1. 整型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-sizeof%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">2.2.</span> <span class="toc-text">2. sizeof关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%B5%AE%E7%82%B9%E5%9E%8B"><span class="toc-number">2.3.</span> <span class="toc-text">3. 浮点型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%AD%97%E7%AC%A6%E5%9E%8B"><span class="toc-number">2.4.</span> <span class="toc-text">4. 字符型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E8%BD%AC%E4%B9%89%E5%AD%97%E7%AC%A6"><span class="toc-number">2.5.</span> <span class="toc-text">5. 转义字符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%9E%8B"><span class="toc-number">2.6.</span> <span class="toc-text">6. 字符串型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E5%B8%83%E5%B0%94%E5%9E%8B"><span class="toc-number">2.7.</span> <span class="toc-text">7. 布尔型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E6%95%B0%E6%8D%AE%E7%9A%84%E8%BE%93%E5%85%A5"><span class="toc-number">2.8.</span> <span class="toc-text">8. 数据的输入</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89-%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.</span> <span class="toc-text">三. 运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.1.</span> <span class="toc-text">1. 算术运算符</span></a></li></ol></li></ol>
      
  </div>
</div>
</div>
      <div class="sidebar-common-sidebar hidden"><div class="sidebar-author">
  <img data-src="/avatar/avatar.webp" data-sizes="auto" alt="LBCH" class="lazyload">
  <div class="sidebar-author-name">LBCH</div>
  <div class="sidebar-description">一个基础的博客网站</div>
</div>
<div class="sidebar-state">
  <div class="sidebar-state-article">
    <div>文章</div>
    <div class="sidebar-state-number">4</div>
  </div>
  <div class="sidebar-state-category">
    <div>分类</div>
    <div class="sidebar-state-number">0</div>
  </div>
  <div class="sidebar-state-tag">
    <div>标签</div>
    <div class="sidebar-state-number">0</div>
  </div>
</div>
<div class="sidebar-social">
  
    <div class="icon-email sidebar-social-icon">
      <a href=mailto:lbc110408@hotmail.com itemprop="url" target="_blank" aria-label="email"></a>
    </div>
  
    <div class="icon-github sidebar-social-icon">
      <a href=https://github.com/LiangBoCh itemprop="url" target="_blank" aria-label="github"></a>
    </div>
  
    <div class="icon-bilibili sidebar-social-icon">
      <a href=https://space.bilibili.com/1874212728 itemprop="url" target="_blank" aria-label="bilibili"></a>
    </div>
  
</div>
<div class="sidebar-menu">
  
    <div class="sidebar-menu-link-wrap">
      <a class="sidebar-menu-link-dummy" href="/" aria-label="首页"></a>
      <span class="sidebar-menu-icon"></span>
      <div class="sidebar-menu-link">首页</div>
    </div>
  
    <div class="sidebar-menu-link-wrap">
      <a class="sidebar-menu-link-dummy" href="/archives" aria-label="归档"></a>
      <span class="sidebar-menu-icon"></span>
      <div class="sidebar-menu-link">归档</div>
    </div>
  
</div>
</div>
    
    
      <div class="sidebar-btn-wrapper" style="position:static">
        <div class="sidebar-toc-btn current"></div>
        <div class="sidebar-common-btn"></div>
      </div>
    
  </div>

  
</aside>

          
        </div>
        <footer id="footer" class="wow fadeInUp">
  <div style="width: 100%; overflow: hidden">
    <div class="footer-line"></div>
  </div>
  <div class="outer">
    <div id="footer-info" class="inner">
      
      <div>
        <span class="icon-copyright"></span>
        2024-2024
        <span class="footer-info-sep"></span>
        LBCH
      </div>
      
        <div>
          基于&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>&nbsp;
          Theme.<a href="https://github.com/D-Sketon/hexo-theme-reimu" target="_blank">Reimu</a>
        </div>
      
      
        <div>
          <span class="icon-brush"></span>
          2.9k
          &nbsp;|&nbsp;
          <span class="icon-coffee"></span>
          00:11
        </div>
      
      
        <div>
          <span class="icon-eye"></span>
          <span id="busuanzi_container_site_pv">总访问量&nbsp;<span id="busuanzi_value_site_pv"></span></span>
          &nbsp;|&nbsp;
          <span class="icon-user"></span>
          <span id="busuanzi_container_site_uv">总访客量&nbsp;<span id="busuanzi_value_site_uv"></span></span>
        </div>
      
    </div>
  </div>
</footer>

        <div class="sidebar-top">
          <img src="/images/taichi.png" height="50" width="50" alt="backtop" />
          <div class="arrow-up"></div>
        </div>
        <div id="mask"></div>
      </div>
      <nav id="mobile-nav">
  <div class="sidebar-wrap">
    
      <div class="sidebar-toc-sidebar"><div class="sidebar-toc">
  <h3 class="toc-title">文章目录</h3>
  <div class="sidebar-toc-wrapper toc-div-class" >
      
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80-%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86"><span class="toc-number">1.</span> <span class="toc-text">一. 基础知识</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%96%87%E5%AD%97%E7%9A%84%E8%BE%93%E5%85%A5%E4%B8%8E%E8%BE%93%E5%87%BA"><span class="toc-number">1.1.</span> <span class="toc-text">1. 文字的输入与输出</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E6%B3%A8%E9%87%8A"><span class="toc-number">1.2.</span> <span class="toc-text">2. 注释</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E5%8F%98%E9%87%8F"><span class="toc-number">1.3.</span> <span class="toc-text">3. 变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%B8%B8%E9%87%8F"><span class="toc-number">1.4.</span> <span class="toc-text">4. 常量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">1.5.</span> <span class="toc-text">5. 关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E6%A0%87%E8%AF%86%E7%AC%A6%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99"><span class="toc-number">1.6.</span> <span class="toc-text">6. 标识符命名规则</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C-%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.</span> <span class="toc-text">二. 数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%95%B4%E5%9E%8B"><span class="toc-number">2.1.</span> <span class="toc-text">1. 整型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-sizeof%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">2.2.</span> <span class="toc-text">2. sizeof关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%B5%AE%E7%82%B9%E5%9E%8B"><span class="toc-number">2.3.</span> <span class="toc-text">3. 浮点型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%AD%97%E7%AC%A6%E5%9E%8B"><span class="toc-number">2.4.</span> <span class="toc-text">4. 字符型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E8%BD%AC%E4%B9%89%E5%AD%97%E7%AC%A6"><span class="toc-number">2.5.</span> <span class="toc-text">5. 转义字符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%9E%8B"><span class="toc-number">2.6.</span> <span class="toc-text">6. 字符串型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E5%B8%83%E5%B0%94%E5%9E%8B"><span class="toc-number">2.7.</span> <span class="toc-text">7. 布尔型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E6%95%B0%E6%8D%AE%E7%9A%84%E8%BE%93%E5%85%A5"><span class="toc-number">2.8.</span> <span class="toc-text">8. 数据的输入</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89-%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.</span> <span class="toc-text">三. 运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.1.</span> <span class="toc-text">1. 算术运算符</span></a></li></ol></li></ol>
      
  </div>
</div>
</div>
      <div class="sidebar-common-sidebar hidden"><div class="sidebar-author">
  <img data-src="/avatar/avatar.webp" data-sizes="auto" alt="LBCH" class="lazyload">
  <div class="sidebar-author-name">LBCH</div>
  <div class="sidebar-description">一个基础的博客网站</div>
</div>
<div class="sidebar-state">
  <div class="sidebar-state-article">
    <div>文章</div>
    <div class="sidebar-state-number">4</div>
  </div>
  <div class="sidebar-state-category">
    <div>分类</div>
    <div class="sidebar-state-number">0</div>
  </div>
  <div class="sidebar-state-tag">
    <div>标签</div>
    <div class="sidebar-state-number">0</div>
  </div>
</div>
<div class="sidebar-social">
  
    <div class="icon-email sidebar-social-icon">
      <a href=mailto:lbc110408@hotmail.com itemprop="url" target="_blank" aria-label="email"></a>
    </div>
  
    <div class="icon-github sidebar-social-icon">
      <a href=https://github.com/LiangBoCh itemprop="url" target="_blank" aria-label="github"></a>
    </div>
  
    <div class="icon-bilibili sidebar-social-icon">
      <a href=https://space.bilibili.com/1874212728 itemprop="url" target="_blank" aria-label="bilibili"></a>
    </div>
  
</div>
<div class="sidebar-menu">
  
    <div class="sidebar-menu-link-wrap">
      <a class="sidebar-menu-link-dummy" href="/" aria-label="首页"></a>
      <span class="sidebar-menu-icon"></span>
      <div class="sidebar-menu-link">首页</div>
    </div>
  
    <div class="sidebar-menu-link-wrap">
      <a class="sidebar-menu-link-dummy" href="/archives" aria-label="归档"></a>
      <span class="sidebar-menu-icon"></span>
      <div class="sidebar-menu-link">归档</div>
    </div>
  
</div>
</div>
    
  </div>
  
    <div class="sidebar-btn-wrapper">
      <div class="sidebar-toc-btn current"></div>
      <div class="sidebar-common-btn"></div>
    </div>
  
</nav>

    </div>
    <div class="site-search">
      <div class="reimu-popup popup">
        <div class="reimu-search">
          <span class="reimu-search-input-icon"></span>
          <div class="reimu-search-input" id="reimu-search-input"></div>
        </div>
        <div class="reimu-results">
          <div id="reimu-stats"></div>
          <div id="reimu-hits"></div>
          <div id="reimu-pagination" class="reimu-pagination"></div>
        </div>
        <span class="popup-btn-close"></span>
      </div>
    </div>
    
<script src="https://npm.webcache.cn/lazysizes@5.3.2/lazysizes.min.js"></script>


<script src="https://npm.webcache.cn/clipboard@2.0.11/dist/clipboard.min.js"></script>



<script src="/js/script.js"></script>



<script src="/js/pjax_script.js" data-pjax></script>


<script type="module" data-pjax>
  import PhotoSwipeLightbox from "https://npm.webcache.cn/photoswipe@5.4.4/dist/photoswipe-lightbox.esm.js";
  
  const pswp = () => {
    if (_$$('.article-entry a.article-gallery-item').length > 0) {
      new PhotoSwipeLightbox({
        gallery: '.article-entry',
        children: 'a.article-gallery-item',
        pswpModule: () => import("https://npm.webcache.cn/photoswipe@5.4.4/dist/photoswipe.esm.js")
      }).init();
    }
    if(_$$('.article-gallery a.article-gallery-item').length > 0) {
      new PhotoSwipeLightbox({
        gallery: '.article-gallery',
        children: 'a.article-gallery-item',
        pswpModule: () => import("https://npm.webcache.cn/photoswipe@5.4.4/dist/photoswipe.esm.js")
      }).init();
    }
    window.lightboxStatus = 'done';
    window.removeEventListener('lightbox:ready', pswp);
  }
  if(window.lightboxStatus === 'ready') {
    pswp()
  } else {
    window.addEventListener('lightbox:ready', pswp);
  }
</script>
















  
<script src="https://npm.webcache.cn/mouse-firework@0.0.4/dist/index.umd.js"></script>

  <script>
    firework(JSON.parse('{"excludeElements":["a","button"],"particles":[{"shape":"circle","move":["emit"],"easing":"easeOutExpo","colors":["#ff5252","#ff7c7c","#ffafaf","#ffd0d0"],"number":20,"duration":[1200,1800],"shapeOptions":{"radius":[16,32],"alpha":[0.3,0.5]}},{"shape":"circle","move":["diffuse"],"easing":"easeOutExpo","colors":["#ff0000"],"number":1,"duration":[1200,1800],"shapeOptions":{"radius":20,"alpha":[0.2,0.5],"lineWidth":6}}]}'))
  </script>






<div id="lazy-script">
  <div>
    
  </div>
</div>


  <script>
    console.log(String.raw`%c 
 ______     ______     __     __    __     __  __    
/\  == \   /\  ___\   /\ \   /\ "-./  \   /\ \/\ \   
\ \  __<   \ \  __\   \ \ \  \ \ \-./\ \  \ \ \_\ \  
 \ \_\ \_\  \ \_____\  \ \_\  \ \_\ \ \_\  \ \_____\ 
  \/_/ /_/   \/_____/   \/_/   \/_/  \/_/   \/_____/ 
                                                  
`,'color: #ff5252;')
    console.log('%c Theme.Reimu v' + '0.2.0' + ' %c https://github.com/D-Sketon/hexo-theme-reimu ', 'color: white; background: #ff5252; padding:5px 0;', 'padding:4px;border:1px solid #ff5252;')
  </script>
  


  
<script src="https://npm.webcache.cn/busuanzi@2.3.0/bsz.pure.mini.js" async></script>


  <!-- hexo injector body_end start -->
<script src="/js/insert_highlight.js" data-pjax></script>
<!-- hexo injector body_end end --></body>
  </html>

